package model

import "errors"

// 错误分类
const (
	ERROR_USER = (iota + 1) * 1000
	CATEGORY
	ARTICLE
)

const (
	SUCCESS        = 0
	ERROR          = 500
	DB_ERROR       = 9001
	DB_OPTION_FAIL = 9002
)

var (
	UserNotFount = errors.New("2")
)

// 用户模块错误
const (
	ERROR_USERNAME_USED = ERROR_USER + iota
	ERROR_PASSWORD_WRONG
	ERROR_USER_NOT_EXIST
	ERROR_TOKEN_EXIST
	ERROR_TOKEN_RUMTIME
	ERROR_TOKEN_WRONG
	ERROR_TOKEN_TYPE_WRONG
)

type Code int

var errMsg = map[Code]string{
	SUCCESS:                "ok",
	ERROR:                  "fail",
	DB_ERROR:               "数据库操作错误",
	DB_OPTION_FAIL:         "操作失败",
	ERROR_USERNAME_USED:    "用户名已存在",
	ERROR_PASSWORD_WRONG:   "密码错误",
	ERROR_USER_NOT_EXIST:   "用户不存在",
	ERROR_TOKEN_EXIST:      "token不存在",
	ERROR_TOKEN_RUMTIME:    "token过期",
	ERROR_TOKEN_WRONG:      "token错误",
	ERROR_TOKEN_TYPE_WRONG: "token格式错误",
}

func (c *Code) GetMsg() string {
	if v, ok := errMsg[*c]; ok {
		return v
	}
	return "未知错误"
}
